import os
import sqlite3

__author__ = 'gongqf'
print os.getcwd()
if os.path.exists(r'e:\web\flask\topshipping'):
    os.chdir(r'e:\web\flask\topshipping')
elif os.path.exists(r'l:\web\flask\topshipping'):
    os.chdir(r'l:\web\flask\topshipping')
elif os.path.exists(r'g:\web\flask\topshipping'):
    os.chdir(r'g:\web\flask\topshipping')

conn=sqlite3.connect(r'..\..\npedi\npedi.db3')
allvsl=conn.execute('select * from allvsl').fetchall()
conn.close()
conn=sqlite3.connect('topshipping.db3')
conn.text_factory = str
for vsl in allvsl:
    if vsl[1][0:2]=="UN":
        imo=vsl[1][-7:]
    else:
        imo=None
    conn.execute("replace into vessel(vesselname,vesselnameen,vesseledicode,vesselimonumber) values(?,?,?,?)",(vsl[3],vsl[2],vsl[1],imo))
conn.commit()
conn.close()